package main

import "fmt"
import "errors"

const ADULT_AGE = 18
const TEST = " am const of test "

var age int
var name string

var User interface {
	getAge() int
}

type Student struct {
	age  int
	name string
}

/**
*注释代码
*
 */
func main() {

	age = -66
	name = " assign name"
	size := "< am size >"
	var height = 6
	//	var height int
	fmt.Println("hello world!!! height is ", name, age, " height is", height, size)
	fmt.Println(" age type os %T ", age)
	fmt.Println("CONST OF ADULT ", ADULT_AGE)

	testConst()

	fmt.Println(" & ", 2&15)

	if age > 0 {
		fmt.Println(" age > 0")
	} else {
		fmt.Println(" age <= 0")
	}

	grade := "D"
	switch {
	case grade == "A":
		fmt.Printf("Excellent!\n")
	case grade == "B", grade == "C":
		fmt.Printf("Well done\n")
	case grade == "D":
		fmt.Printf("You passed\n")
	case grade == "F":
		fmt.Printf("Better try again\n")
	default:
		fmt.Printf("Invalid grade\n")
	}
	fmt.Printf("Your grade is  %s\n", grade)

	var x interface{}

	switch i := x.(type) {
	case nil:
		fmt.Printf("type of x :%T", i)
	case int:
		fmt.Printf("x is int")
	case float64:
		fmt.Printf("x is float64")
	case func(int) float64:
		fmt.Printf("x is func(int)")
	case bool, string:
		fmt.Printf("x is bool or string")
	default:
		fmt.Printf("don't know the type")
	}

	fmt.Println("===================循环语句测试=================")

	index := 1
	for true {
		index++
		fmt.Println(index)
		if index > 10 {
			break
		}
	}

	fmt.Println(" length of name : ", len(name))

	fmt.Println("===================传参传值测试=================")
	testFunc(&age, &name)
	var age2 = &age
	fmt.Println("age is : ", age, " name is :", name, " age2 :", *age2)

	var stu = Student{1, "am name"}

	testFuncStruct(&stu)

	fmt.Println("stu.age = ", stu.age, " stu.name =", stu.name)

	fmt.Println("===================intreface测试=================")
	var stu2 = Student{11, "stu2"}
	var age = stu2.getAge()
	fmt.Println("age=", age, " stu2.age", stu2.age)

	//新建异常抛出
	error := errors.New("Math: negative number passed to Sqrt")
	fmt.Println(error == nil)

}

func testConst() {
	fmt.Println("====>", TEST)
}

/**方法参数和返回值测试,默认传入是传值的，所以需要添加*号表示传参*/
func testFunc(age *int, name1 *string) {
	//	var modifyName string
	var modifyAge int
	//	modifyName = " modified name value !!!"
	modifyAge = 909

	*name1 = " modified name value !!!"
	*age = modifyAge
}

func testFuncStruct(stu *Student) {
	stu.age = 999
	stu.name = "testFuncStruct modified"
}

func (stu *Student) getAge() int {
	stu.age *= 100
	return stu.age
}
